﻿using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Read.API.Command.MenuCommand;
using MediatR;

namespace B.S.BaseData.Read.API.CommandHandler.MenuHandler
{
    public class SelectIdDelHandler : IRequestHandler<SelectIdDelCommand, APIResult<List<MenuManagement>>>
    {
        public readonly IBaseRepository<MenuManagement> _baseRepository;

        public SelectIdDelHandler(IBaseRepository<MenuManagement> baseRepository)
        {
            _baseRepository = baseRepository;
        }

        public async Task<APIResult<List<MenuManagement>>> Handle(SelectIdDelCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<MenuManagement>> result = new APIResult<List<MenuManagement>>();
            result.Code = APIEnum.Success;
            result.Msg = "查询成功";

            var entity = _baseRepository.GetAll().Where(p => p.ParentId == request.MenuId).ToList();
            result.Data = entity;
            return await Task.FromResult(result);
        }
    }
}
